package com.myyl.springcloudprovider.controller;

import com.myyl.springcloudprovider.pojo.User;
import com.myyl.springcloudprovider.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: myyl
 * @Time: 2019/7/19 - 22:15
 * @Description:
 */

@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public User getUserById(@PathVariable String id, HttpServletRequest httpServletRequest) {
        /*try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        System.out.println(httpServletRequest.getLocalAddr() + ":" + httpServletRequest.getServerPort());
        return userService.getUserById(id);
    }

}
